package cn.tedu._04mvcboot01.controller;

import cn.tedu._04mvcboot01.pojo.dto.UserLoginDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Controller注解: 将此类标识为控制器的类,负责接收请求
 */
@Controller
public class UserController {
    /**
     * RequestMapping注解:请求注解;
     * ResponseBody注解:响应注解,允许控制器方法以返回值的形式返回给客户端数据
     * http://localhost:8080/v1/users/login
     */
    /*
    @RequestMapping("/v1/users/login")
    @ResponseBody
    public String login(HttpServletRequest request){
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        return username + ":" + password;
    }*/

    /**
     * 方式2: 声明参数方式接收客户端传递的数据
     */
    /*
    @RequestMapping("/v1/users/login")
    @ResponseBody
    public String login(String username, String password){
        return username + ":" + password;
    }*/

    /**
     * 方式3: 声明POJO类[DTO类]方式接收客户端传递的数据
     */
    @RequestMapping("/v1/users/login")
    @ResponseBody
    public String login(UserLoginDTO userLoginDTO){
        //soutp + 回车
        System.out.println("userLoginDTO = " + userLoginDTO);
        String username = userLoginDTO.getUsername();
        String password = userLoginDTO.getPassword();

        return username + ":" + password;
    }
}








